import { useEffect, useRef } from 'react';



const PAGE_SIZE = 10;
/**
 *
 * @param server : function
 * @param options : object
 */
export function useFlatList(server, options = {}) {
    const loadingMoreLock = useRef();
    let listLength = useRef(0);

    useEffect(
        () => {
            if (loadingMoreLock.current && result.loadingMore === false) {
                loadingMoreLock.current = false;
            }
        },
        [result.loadingMore]
    );
    return {
        ...result,
        list: result?.data?.list,
        data: result?.data,
        loadMore: () => {
            if (!loadingMoreLock.current) {
                result.loadMore();
                loadingMoreLock.current = true;
            }
        }
    };
}
